import sys
sys.path.append('../kernel')
from model import Model
class TaskModel(Model):
    def __init__(self):
        #链接数据库
        super().__init__()
    #获取任务数据
    def get_task(self):
        # 执行查询
        #sql = "select id,web_url,trait,web_http,c_id from cg_task WHERE id=2"
        sql = "select id,web_url,trait,web_http,c_id from cg_task"
        self.cursor.execute(sql)
        data=self.cursor.fetchall()
        return data
    
    #根据id获取任务信息
    def get_task_by_id(self,id):
        sql = "select id,web_url,trait,web_http,c_id from cg_task where id=%s"
        self.cursor.execute(sql,[id])
        data=self.cursor.fetchone()
        return data

    def __del__(self):
        #计数数据库链接
        self.cursor.close()
        self.conn.close()